class Pid:
    def __init__(self, kp, ki, kd, exp_val=0, dt=1):
        self.dt = dt
        self.KP = kp
        self.KI = ki
        self.KD = kd
        self.exp_val = exp_val
        self.now_val = 0
        self.sum_err = 0
        self.now_err = 0
        self.last_err = 0

    def calculate(self):
        self.last_err = self.now_err
        self.now_err = self.exp_val - self.now_val
        self.sum_err += self.now_err

        self.now_val = (
            self.KP * self.now_err
            + self.KI * self.sum_err
            + self.KD * (self.now_err - self.last_err)
        )

        return self.now_val
